#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023-5-13 10:57
# @Author  : XiangZhi_an
# @File    : req.py
# @Description :
import requests
import json

# 注册
# register_url = 'http://127.0.0.1:5000/register'
headers = {'Content-Type': 'application/json'}
# data = {
#     'username': 'example_user12',
#     'password': '1',
#     'email': 'example_email@example.com'
# }
# response = requests.post(register_url, headers=headers, data=json.dumps(data))
# if response.ok:
#     response_json = response.json()
#     print(response_json)
#     if response_json['status'] == 'success':
#         print('User registered successfully')
#     else:
#         print('Registration failed')
# else:
#     print('Request failed')

# 登录
login_url = 'http://127.0.0.1:5000/login'
data = {
    'username': '123',
    'password': '456'
}
response = requests.post(login_url, headers=headers, data=json.dumps(data))
print(response.text)
print(response)
print(response.status_code)
if response.ok:
    response_json = response.json()
    if response_json['status'] == 'success':
        access_token = response_json['access_token']
        print('Logged in successfully')
    else:
        print('Login failed')
else:
    print('Request failed')
